package com.example.service.webhook.business.taobao.repository;

import com.example.service.webhook.business.taobao.entity.RecentAddressEntity;
import com.example.service.webhook.business.taobao.entity.TaobaoAlipayWealthEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author liyang
 * @email liyang@51dojo.com
 * @create 2017-10-24 下午4:00
 * @description 淘宝对应支付宝crud
 **/
@Repository
public class TaobaoAlipayWealthRepository extends BaseDAO<TaobaoAlipayWealthEntity>{

    @Resource(name="templateTaobao")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void saveAlipayWealth(TaobaoAlipayWealthEntity entity)throws Exception  {
        entity.setCreateTime(DateUtil.getCurrentDate());
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.add(entity);
    }

    public void updateAlipayWealth(TaobaoAlipayWealthEntity entity) throws Exception  {
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.modify(entity);
    }

    public TaobaoAlipayWealthEntity getAlipayWealth(String userId,String mappingId) throws Exception {
        String sql = "";
        String tableName = "t_taobao_alipaywealth";
        sql = "select * from " + tableName + " where userId=? and mappingId=?";
        TaobaoAlipayWealthEntity pojo = null;
        try{
            pojo = (TaobaoAlipayWealthEntity) queryOne(sql, new Object[] { userId,mappingId}, new TaobaoAlipayWealthEntity());
        }catch(EmptyResultDataAccessException e){
            return null;
        }

        return pojo;
    }

}
